package com.lindroy.androidplayer.viewmodels

import androidx.lifecycle.viewModelScope
import androidx.paging.cachedIn
import com.lindroy.androidplayer.logic.network.repository.Repository
import com.lindroy.androidplayer.utils.SingleLiveEvent
import com.lindroy.androidplayer.utils.mapItem
import com.lindroy.androidplayer.utils.mapSingle

/**
 * @author Lin
 * @date 2022/2/18
 * @function
 */
class CollectedArticleViewModel : PageViewModel() {

    private val itemCLickAction = SingleLiveEvent<CollectedArticleItemViewModel>()

    val itemClickLiveData = itemCLickAction.mapSingle { it }

    val collectionArticleList = Repository.collectedArticles.mapItem {
        CollectedArticleItemViewModel(
            id = it.id,
            title = it.title,
            desc = it.desc,
            author = it.author,
            chapterName = it.chapterName,
            link = it.link,
            niceDate = it.niceDate,
            itemClickListener = itemCLickAction
        )
    }.cachedIn(viewModelScope)

}